package com.ksyun.campus.client.domain;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;

public enum FileType
{
    @JsonProperty("UNKNOWN")
    Unknown(0),  
    @JsonProperty("VOLUME") 
    Volume(1),  
    @JsonProperty("FILE")
    File(2),  
    @JsonProperty("DIRECTORY")
    Directory(3);

    private int code;
    FileType(int code) {
        this.code=code;
    }
    
    @JsonValue
    public String getValue() {
        switch (this) {
            case Unknown: return "UNKNOWN";
            case Volume: return "VOLUME";
            case File: return "FILE";
            case Directory: return "DIRECTORY";
            default: return "UNKNOWN";
        }
    }
    
    @JsonCreator
    public static FileType fromValue(String value) {
        if (value == null) return Unknown;
        switch (value.toUpperCase()) {
            case "UNKNOWN": return Unknown;
            case "VOLUME": return Volume;
            case "FILE": return File;
            case "DIRECTORY":
            case "DIR": return Directory;  // 支持两种格式
            default: return Unknown;
        }
    }
    public int getCode(){
        return code;
    }
    public static FileType get(int code){
        switch (code){
            case 1:
                return Volume;
            case 2:
                return File;
            case 3:
                return Directory;
            default:
                return Unknown;
        }
    }
}
